package com.cp.admin.modular.system.controller;

import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.system.model.TaskDict;
import com.cp.admin.modular.system.service.ITaskDictService;

/**
 * 系统任务信息控制器
 *
 * @author fengshuonan
 * @Date 2020-03-02 13:07:15
 */
@Controller
@RequestMapping("/taskDict")
public class TaskDictController extends BaseController {

    private String PREFIX = "/system/taskDict/";

    @Autowired
    private ITaskDictService taskDictService;

    /**
     * 跳转到系统任务信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "taskDict.html";
    }

    /**
     * 跳转到添加系统任务信息
     */
    @RequestMapping("/taskDict_add")
    public String taskDictAdd() {
        return PREFIX + "taskDict_add.html";
    }

    /**
     * 跳转到修改系统任务信息
     */
    @RequestMapping("/taskDict_update/{taskDictId}")
    public String taskDictUpdate(@PathVariable Long taskDictId, Model model) {
        TaskDict taskDict = taskDictService.selectById(taskDictId);
        model.addAttribute("item",taskDict);
        LogObjectHolder.me().set(taskDict);
        return PREFIX + "taskDict_edit.html";
    }

    /**
     * 获取系统任务信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return taskDictService.selectList(null);
    }

    /**
     * 新增系统任务信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TaskDict taskDict) {
        taskDictService.insert(taskDict);
        return SUCCESS_TIP;
    }

    /**
     * 删除系统任务信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long taskDictId) {
        taskDictService.deleteById(taskDictId);
        return SUCCESS_TIP;
    }

    /**
     * 修改系统任务信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TaskDict taskDict) {
        taskDictService.updateById(taskDict);
        return SUCCESS_TIP;
    }

    /**
     * 系统任务信息详情
     */
    @RequestMapping(value = "/detail/{taskDictId}")
    @ResponseBody
    public Object detail(@PathVariable("taskDictId") Long taskDictId) {
        return taskDictService.selectById(taskDictId);
    }
}
